home *** CD-ROM | disk | FTP | other *** search
-
-
-
- bbbbsssseeeeaaaarrrrcccchhhh((((3333CCCC)))) bbbbsssseeeeaaaarrrrcccchhhh((((3333CCCC))))
-
-
-
- NNNNAAAAMMMMEEEE
- _bbbb_ssss_eeee_aaaa_rrrr_cccc_hhhh - binary search a sorted table
-
- SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_llll_iiii_bbbb_...._hhhh_>>>>
-
- _vvvv_oooo_iiii_dddd _****_bbbb_ssss_eeee_aaaa_rrrr_cccc_hhhh _((((_cccc_oooo_nnnn_ssss_tttt _vvvv_oooo_iiii_dddd _****_kkkk_eeee_yyyy_,,,, _cccc_oooo_nnnn_ssss_tttt _vvvv_oooo_iiii_dddd _****_bbbb_aaaa_ssss_eeee_,,,, _ssss_iiii_zzzz_eeee______tttt _nnnn_eeee_llll_,,,,
- _ssss_iiii_zzzz_eeee______tttt _ssss_iiii_zzzz_eeee_,,,, _iiii_nnnn_tttt _((((_****_cccc_oooo_mmmm_pppp_aaaa_rrrr_))))_((((_cccc_oooo_nnnn_ssss_tttt _vvvv_oooo_iiii_dddd _****_,,,, _cccc_oooo_nnnn_ssss_tttt _vvvv_oooo_iiii_dddd _****_))))_))))_;;;;
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- _bbbb_ssss_eeee_aaaa_rrrr_cccc_hhhh is a binary search routine generalized from Knuth (6.2.1)
- Algorithm B. It returns a pointer into a table (an array) indicating
- where a datum may be found or a null pointer if the datum cannot be
- found. The table must be previously sorted in increasing order according
- to a comparison function pointed to by _c_o_m_p_a_r. _k_e_y points to a datum
- instance to be sought in the table. _b_a_s_e points to the element at the
- base of the table. _n_e_l is the number of elements in the table. _s_i_z_e is
- the number of bytes in each element. The function pointed to by _c_o_m_p_a_r
- is called with two arguments that point to the elements being compared.
- The function must return an integer less than, equal to, or greater than
- 0 as accordingly the first argument is to be considered less than, equal
- to, or greater than the second.
-
- EEEEXXXXAAAAMMMMPPPPLLLLEEEE
- The example below searches a table containing pointers to nodes
- consisting of a string and its length. The table is ordered
- alphabetically on the string in the node pointed to by each entry.
-
- This program reads in strings and either finds the corresponding node and
- prints out the string and its length, or prints an error message.
-
- _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_iiii_oooo_...._hhhh_>>>>
- _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_llll_iiii_bbbb_...._hhhh_>>>>
- _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_rrrr_iiii_nnnn_gggg_...._hhhh_>>>>
-
- _ssss_tttt_rrrr_uuuu_cccc_tttt _nnnn_oooo_dddd_eeee _{{{{ _////_**** _tttt_hhhh_eeee_ssss_eeee _aaaa_rrrr_eeee _ssss_tttt_oooo_rrrr_eeee_dddd _iiii_nnnn _tttt_hhhh_eeee _tttt_aaaa_bbbb_llll_eeee _****_////
- _cccc_hhhh_aaaa_rrrr _****_ssss_tttt_rrrr_iiii_nnnn_gggg_;;;;
- _iiii_nnnn_tttt _llll_eeee_nnnn_gggg_tttt_hhhh_;;;;
- _}}}}_;;;;
- _ssss_tttt_aaaa_tttt_iiii_cccc _ssss_tttt_rrrr_uuuu_cccc_tttt _nnnn_oooo_dddd_eeee _tttt_aaaa_bbbb_llll_eeee_[[[[_]]]] _==== _////_**** _tttt_aaaa_bbbb_llll_eeee _tttt_oooo _bbbb_eeee _ssss_eeee_aaaa_rrrr_cccc_hhhh_eeee_dddd _****_////
- _{{{{
- _{{{{ _""""_aaaa_ssss_pppp_aaaa_rrrr_aaaa_gggg_uuuu_ssss_""""_,,,, _1111_0000 _}}}}_,,,,
- _{{{{ _""""_bbbb_eeee_aaaa_nnnn_ssss_""""_,,,, _6666 _}}}}_,,,,
- _{{{{ _""""_tttt_oooo_mmmm_aaaa_tttt_oooo_""""_,,,, _7777 _}}}}_,,,,
- _{{{{ _""""_wwww_aaaa_tttt_eeee_rrrr_mmmm_eeee_llll_oooo_nnnn_""""_,,,, _1111_1111 _}}}}_,,,,
- _}}}}_;;;;
-
- _mmmm_aaaa_iiii_nnnn_((((_))))
- _{{{{
- _ssss_tttt_rrrr_uuuu_cccc_tttt _nnnn_oooo_dddd_eeee _****_nnnn_oooo_dddd_eeee______pppp_tttt_rrrr_,,,, _nnnn_oooo_dddd_eeee_;;;;
- _////_**** _rrrr_oooo_uuuu_tttt_iiii_nnnn_eeee _tttt_oooo _cccc_oooo_mmmm_pppp_aaaa_rrrr_eeee _2222 _nnnn_oooo_dddd_eeee_ssss _****_////
- _ssss_tttt_aaaa_tttt_iiii_cccc _iiii_nnnn_tttt _nnnn_oooo_dddd_eeee______cccc_oooo_mmmm_pppp_aaaa_rrrr_eeee_((((_cccc_oooo_nnnn_ssss_tttt _vvvv_oooo_iiii_dddd _****_,,,, _cccc_oooo_nnnn_ssss_tttt _vvvv_oooo_iiii_dddd _****_))))_;;;;
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- bbbbsssseeeeaaaarrrrcccchhhh((((3333CCCC)))) bbbbsssseeeeaaaarrrrcccchhhh((((3333CCCC))))
-
-
-
- _cccc_hhhh_aaaa_rrrr _ssss_tttt_rrrr______ssss_pppp_aaaa_cccc_eeee_[[[[_2222_0000_]]]]_;;;; _////_**** _ssss_pppp_aaaa_cccc_eeee _tttt_oooo _rrrr_eeee_aaaa_dddd _ssss_tttt_rrrr_iiii_nnnn_gggg _iiii_nnnn_tttt_oooo _****_////
-
- _nnnn_oooo_dddd_eeee_...._ssss_tttt_rrrr_iiii_nnnn_gggg _==== _ssss_tttt_rrrr______ssss_pppp_aaaa_cccc_eeee_;;;;
- _wwww_hhhh_iiii_llll_eeee _((((_ssss_cccc_aaaa_nnnn_ffff_((((_""""_%%%%_2222_0000_ssss_""""_,,,, _nnnn_oooo_dddd_eeee_...._ssss_tttt_rrrr_iiii_nnnn_gggg_)))) _!!!!_==== _EEEE_OOOO_FFFF_)))) _{{{{
- _nnnn_oooo_dddd_eeee______pppp_tttt_rrrr _==== _bbbb_ssss_eeee_aaaa_rrrr_cccc_hhhh_(((( _&&&&_nnnn_oooo_dddd_eeee_,,,,
- _tttt_aaaa_bbbb_llll_eeee_,,,, _ssss_iiii_zzzz_eeee_oooo_ffff_((((_tttt_aaaa_bbbb_llll_eeee_))))_////_ssss_iiii_zzzz_eeee_oooo_ffff_((((_ssss_tttt_rrrr_uuuu_cccc_tttt _nnnn_oooo_dddd_eeee_))))_,,,,
- _ssss_iiii_zzzz_eeee_oooo_ffff_((((_ssss_tttt_rrrr_uuuu_cccc_tttt _nnnn_oooo_dddd_eeee_))))_,,,, _nnnn_oooo_dddd_eeee______cccc_oooo_mmmm_pppp_aaaa_rrrr_eeee_))))_;;;;
- _iiii_ffff _((((_nnnn_oooo_dddd_eeee______pppp_tttt_rrrr _!!!!_==== _NNNN_UUUU_LLLL_LLLL_)))) _{{{{
- _((((_vvvv_oooo_iiii_dddd_)))) _pppp_rrrr_iiii_nnnn_tttt_ffff_((((_""""_ssss_tttt_rrrr_iiii_nnnn_gggg _==== _%%%%_2222_0000_ssss_,,,, _llll_eeee_nnnn_gggg_tttt_hhhh _==== _%%%%_dddd_\\\\_nnnn_""""_,,,,
- _nnnn_oooo_dddd_eeee______pppp_tttt_rrrr_----_>>>>_ssss_tttt_rrrr_iiii_nnnn_gggg_,,,, _nnnn_oooo_dddd_eeee______pppp_tttt_rrrr_----_>>>>_llll_eeee_nnnn_gggg_tttt_hhhh_))))_;;;;
- _}}}} _eeee_llll_ssss_eeee _{{{{
- _((((_vvvv_oooo_iiii_dddd_))))_pppp_rrrr_iiii_nnnn_tttt_ffff_((((_""""_nnnn_oooo_tttt _ffff_oooo_uuuu_nnnn_dddd_:::: _%%%%_2222_0000_ssss_\\\\_nnnn_""""_,,,, _nnnn_oooo_dddd_eeee_...._ssss_tttt_rrrr_iiii_nnnn_gggg_))))_;;;;
- _}}}}
- _}}}}
- _rrrr_eeee_tttt_uuuu_rrrr_nnnn_((((_0000_))))_;;;;
- _}}}}
-
- _////_**** _rrrr_oooo_uuuu_tttt_iiii_nnnn_eeee _tttt_oooo _cccc_oooo_mmmm_pppp_aaaa_rrrr_eeee _tttt_wwww_oooo _nnnn_oooo_dddd_eeee_ssss _bbbb_aaaa_ssss_eeee_dddd _oooo_nnnn _aaaa_nnnn _****_////
- _////_**** _aaaa_llll_pppp_hhhh_aaaa_bbbb_eeee_tttt_iiii_cccc_aaaa_llll _oooo_rrrr_dddd_eeee_rrrr_iiii_nnnn_gggg _oooo_ffff _tttt_hhhh_eeee _ssss_tttt_rrrr_iiii_nnnn_gggg _ffff_iiii_eeee_llll_dddd _****_////
- _ssss_tttt_aaaa_tttt_iiii_cccc _iiii_nnnn_tttt
- _nnnn_oooo_dddd_eeee______cccc_oooo_mmmm_pppp_aaaa_rrrr_eeee_((((_cccc_oooo_nnnn_ssss_tttt _vvvv_oooo_iiii_dddd _****_nnnn_oooo_dddd_eeee_1111_,,,, _cccc_oooo_nnnn_ssss_tttt _vvvv_oooo_iiii_dddd _****_nnnn_oooo_dddd_eeee_2222_))))
- _{{{{
- _rrrr_eeee_tttt_uuuu_rrrr_nnnn _((((_ssss_tttt_rrrr_cccc_mmmm_pppp_((((
- _((((_((((_cccc_oooo_nnnn_ssss_tttt _ssss_tttt_rrrr_uuuu_cccc_tttt _nnnn_oooo_dddd_eeee _****_))))_nnnn_oooo_dddd_eeee_1111_))))_----_>>>>_ssss_tttt_rrrr_iiii_nnnn_gggg_,,,,
- _((((_((((_cccc_oooo_nnnn_ssss_tttt _ssss_tttt_rrrr_uuuu_cccc_tttt _nnnn_oooo_dddd_eeee _****_))))_nnnn_oooo_dddd_eeee_2222_))))_----_>>>>_ssss_tttt_rrrr_iiii_nnnn_gggg_))))_))))_;;;;
- _}}}}
-
- SSSSEEEEEEEE AAAALLLLSSSSOOOO
- _hhhh_ssss_eeee_aaaa_rrrr_cccc_hhhh(3C), _llll_ssss_eeee_aaaa_rrrr_cccc_hhhh(3C), _qqqq_ssss_oooo_rrrr_tttt(3C), _tttt_ssss_eeee_aaaa_rrrr_cccc_hhhh(3C).
-
- DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
- A null pointer is returned if the key cannot be found in the table.
-
- NNNNOOOOTTTTEEEESSSS
- The pointers to the key and the element at the base of the table should
- be of type pointer-to-_e_l_e_m_e_n_t.
-
- The comparison function need not compare every byte, so arbitrary data
- may be contained in the elements in addition to the values being
- compared.
-
- If the number of elements in the table is less than the size reserved for
- the table, _n_e_l should be the lower number.
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-